#!/usr/bin/python
#+------------------------------------------------------------------------------
#|
#| FILENAME: build_fix_errors.py
#|
#| PROJECT: Cairo Libraries
#|
#| FILE DESCRIPTION:
#|    This is a temporary script to fix build errors caused by char*
#|    casts in the SWIG python generated output under windows 
#|    until I can find a permanent solution.
#|
#+------------------------------------------------------------------------------
#|
#| Cairolib is a series of extensions, examples, and libraries for the
#| Cairo graphics package (see http://www.cairographics.org).
#| 
#| Copyright (C) 2006  Bradford Elliott
#|
#| This library is free software; you can redistribute it and/or
#| modify it under the terms of the GNU Lesser General Public
#| License as published by the Free Software Foundation; either
#| version 2.1 of the License, or (at your option) any later version.
#| 
#| This library is distributed in the hope that it will be useful,
#| but WITHOUT ANY WARRANTY; without even the implied warranty of
#| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#| Lesser General Public License for more details.
#| 
#| You should have received a copy of the GNU Lesser General Public
#| License along with this library; if not, write to the Free Software
#| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#| 
#+------------------------------------------------------------------------------
import re

# Open the generated SWIG file that contains the errors
source = open("cairolib_wrap.cxx", "r")
contents = source.read()
source.close()

# Now replace to lines that complain. Should really use a const cast
# but I'll just do it simple for now.
src1_expr = re.compile("(char \*doc = )(\(\(\(PyCFunctionObject \*\)obj\) -> m_ml -> ml_doc\);)")
contents = src1_expr.sub("\\1 (char*)\\2", contents)

src2_expr = re.compile("(char \*c = )(methods\[i\]\.ml_doc;)")
contents = src2_expr.sub("\\1 (char*)\\2", contents)

# Re-open the file and replace it with the corrected version.
source = open("cairolib_wrap.cxx", "w")
source.write(contents)
source.close()
